package com.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.RoleMenu;
import com.example.mapper.MenuMapper;
import com.example.mapper.RoleMenuMapper;
import com.example.service.IRoleMenuService;
import com.example.utils.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 王鹤蒲
 * @since 2023-08-13
 */
@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> implements IRoleMenuService {

    private final static Logger log= LoggerFactory.getLogger(RoleMenuServiceImpl.class);

    @Autowired
    private RoleMenuMapper roleMenuMapper;
    @Autowired
    private MenuMapper menuMapper;

    @Override
    @Transactional
    public void insertBatch(Integer roleId, List<Integer> menuIds) {
        roleMenuMapper.deleteByRoleId(roleId);
        for (Integer menuId:menuIds) {
            roleMenuMapper.insert(new RoleMenu().setRoleId(roleId).setMenuId(menuId));
        }
    }



    @Override
    public R selectMenuIdByRoleId(Integer roleId) {
       return R.success(roleMenuMapper.selectMenuIdsByRoleId(roleId));

    }
}
